package Model;

import java.io.InputStream;
import java.net.URL;
import javazoom.jl.player.advanced.AdvancedPlayer;

public class PlayerThread implements Runnable {
	private static PlayerThread single;
	public boolean waiting;
	public static String path;


	@SuppressWarnings("static-access")
	private PlayerThread(String path){
		this.path = path;
		waiting = false;
	}

	public static String getPath() {
		return path;
	}

	public static void setPath(String path) {
		PlayerThread.path = path;
	}

	@Override
	public void run(){
		while(!waiting){

			try{
				URL url = new URL(path);
				InputStream in = url.openStream();
				AdvancedPlayer pl = new AdvancedPlayer(in);
				pl.play();

			}
			catch(Exception e){
				System.out.println("Error: "+e);
		}
		}
	}

	public void setWaiting(boolean waiting){
		this.waiting = waiting;
	}
	public static synchronized PlayerThread getInstance(){
		if(single == null){
			single = new PlayerThread(path);
			
		}
	return single;
	}
}
